<h3 class="title">
	&nbsp;首页 &gt; <a href="?c=store">餐厅管理</a> &gt;
<?php
	$acts = array(
		'create' => '添加',
		'modify' => '编辑',
	);
	echo $acts[$action];
?>
</h3>

<form method="post" name="form1" action="<?=Base::adminUrl('store', 'process');?>" enctype="multipart/form-data" onsubmit="return checkSubmit();">
  <input type="hidden" name="action" value="<?=$action;?>" />
  <input type="hidden" name="res_id" value="<?=$data['res_id'];?>" />
  <div class="tags">
    <div id="tagstitle">
    <a href="#" id="one1" onclick="setTab('one',1,4)" class="hover">基本信息</a>
    <a href="#" id="one2" onclick="setTab('one',2,4)">送餐规则</a>
    <a href="#" id="one3" onclick="setTab('one',3,4)">配送区域</a>
    <a href="#" id="one4" onclick="setTab('one',4,4)">其他项目</a>
    </div>
    <div id="tagscontent">
      <div id="con_one_1">
        <table width="100%" border="0" cellspacing="2" cellpadding="0" id="table1" class="formtable">
          <tr>
            <td width="19%" align="right"><span class="title">所属分类</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><select id="cat_id" name="cat_id" class="ssel">
                <option value="0" selected>请选择...</option>
              </select>
              &nbsp;<font color="red">*</font> <span class="tips">顶级栏目可跳过</span></td>
          </tr>          <tr>
            <td width="19%" align="right"><span class="title">餐厅名称</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="name" id="name" size="40" class="skey-l" value="<?=h($data['name']);?>" />
              &nbsp;<font color="red">*</font></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">别名</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="nickname" id="nickname" size="40" class="skey-l" value="<?=h($data['nickname']);?>" />
             <span class="tips"><a href="javascript:tipsbox('可填写缩略语，或者更完整的称谓');">查看帮助</a></span></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">详细地址</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%">
    		  <select id="zone_id" name="zone_id" class="ssel" sel="<?=intval($data['zone_id']);?>">
                <option value="0" selected>请选择...</option>
              </select>
              <select id="subzone_id" name="subzone_id" class="ssel" sel="<?=intval($data['subzone_id']);?>">
                <option value="0" selected>请选择...</option>
              </select>
              &nbsp;<font color="red">*</font>
              <br />
              <input type="text" name="address" id="address" size="40" class="skey-l" value="<?=h($data['address']);?>" />
              &nbsp;<font color="red">*</font></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">营业时间</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%">
            <select name="service_time[0]" id="service_time_0" class="ssel">
            <option value="" selected>请选择...</option>
            <?php echo store_time_option(0, 23.5, $data['service_time'][0]);?>
            </select>
            ~
            <select name="service_time[1]" id="service_time_1" class="ssel">
            <option value="" selected>请选择...</option>
            <?php echo store_time_option(0.5, 24, $data['service_time'][1]);?>
            </select>
            &nbsp;<font color="red">*</font> <span class="tips"><a href="javascript:tipsbox('若为24小时营业，可选择00：00~00：00');">查看帮助</a></span></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">付款方式</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%">
              <input name="payment" type="radio" id="payment_1" value="1" checked="checked"  />
              <label for="payment_1">餐到付款</label>&nbsp;&nbsp;
              <input name="payment" type="radio" id="payment_2" value="2" disabled />
              <label for="payment_2">在线付款</label>&nbsp;&nbsp;
              <input name="payment" type="radio" id="payment_3" value="3" disabled />
              <label for="payment_3">餐到或在线付款</label>&nbsp;&nbsp;
            </td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">400分机号码</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="call_number" id="call_number" size="40" class="skey-l" value="<?=intval($data['call_number']);?>"/>
            &nbsp;<font color="red">*</font> <span class="tips"><a href="javascript:tipsbox('请填写400分机号码，若为0则前台显示订餐电话');">查看帮助</a></span></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">主订餐电话</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="telphone" id="telphone" size="40" class="skey-l" value="<?=h($data['telphone']);?>" />
            &nbsp;<font color="red">*</font> <span class="tips"><a href="javascript:tipsbox('前台显示的主订餐电话');">查看帮助</a></span></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">订餐电话 2</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="telphone2" id="telphone2" size="40" class="skey-l" value="<?=h($data['telphone2']);?>" /></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">订餐电话 3</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="telphone3" id="telphone3" size="40" class="skey-l" value="<?=h($data['telphone3']);?>" /></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">排序</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="ordnum" id="ordnum" size="40" class="skey-l" value="<?=h($data['ordnum']);?>" /></td>
          </tr>
        </table>
      </div>
      <div id="con_one_2" style="display:none">
        <table width="100%" border="0" cellspacing="2" cellpadding="0" id="table2" class="formtable">
          <tr>
            <td width="19%" align="right"><span class="title">最低消费（元）</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="min_charge" id="min_charge" size="40" class="skey-l" value="<?=intval($data['min_charge']);?>" />
              &nbsp;<font color="red">*</font> <span class="tips"><a href="javascript:tipsbox('设置餐厅最低消费金额，若为 0 则为不限制">查看帮助</a></span></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">起送份数（份）</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="min_order" id="min_order" size="40" class="skey-l" value="<?=intval($data['min_order']);?>" />
            &nbsp;<font color="red">*</font> <span class="tips"><a href="javascript:tipsbox('设置餐厅送餐最低份数，最少为 1 份');">查看帮助</a></span></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">送餐费规则</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><input type="text" name="extra_pay" id="extra_pay" size="40" class="skey-l" value="<?=h($data['extra_pay']);?>" />
             <span class="tips"><a href="javascript:tipsbox('请详细填写，留空为免费。如：“2公里内免费，2公里外10元 ...”');">查看帮助</a></span></td>
          </tr>
          <tr>
          	<td width="19%" align="right"><span class="title">送餐时间</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%">
            <select name="delivery_time[0]" id="delivery_time_0" class="ssel">
            <option value="" selected>请选择...</option>
            <?php echo store_time_option(6, 20, $data['delivery_time'][0]);?>
            </select>
            ~
            <select name="delivery_time[1]" id="delivery_time_1" class="ssel">
            <option value="" selected>请选择...</option>
            <?php echo store_time_option(10, 24, $data['delivery_time'][1]);?>
            </select>
            <br />
            <select name="delivery_time[2]" id="delivery_time_2" class="ssel">
            <option value="" selected>请选择...</option>
            <?php echo store_time_option(13, 20, $data['delivery_time'][2]);?>
            </select>
            ~
            <select name="delivery_time[3]" id="delivery_time_3" class="ssel">
            <option value="" selected>请选择...</option>
            <?php echo store_time_option(14, 24, $data['delivery_time'][3]);?>
            </select>

            </td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">配送范围</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><textarea class="stxt" rows="6" cols="40" id="delivery_area" name="delivery_area"><?=h($data['delivery_area']);?></textarea></td>
          </tr>
        </table>
      </div>
      <div id="con_one_3" style="display:none">
        <table width="100%" border="0" cellspacing="2" cellpadding="0" id="table3" class="formtable">
          <tr>
            <td width="19%" align="right"><span class="title">配送区域设置</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%">
			<input type="checkbox" name="city_deliver" id="city_deliver" value="1" <?php if($data['city_deliver']) echo 'checked';?> />
            <label for="city_deliver">全市配送</label>

            <table width="98%" border="0" cellspacing="2" cellpadding="0" id="zone_deliver" class="formtable"
            		 style="border:1px #ccc solid;<?php if($data['city_deliver']) echo 'display:none';?>">
            <?php
				$cache = Cache::get('system.zone');
				$cdata = $cache['data'];
				$index = $cache['index'];

				$zone  = Base::loadModule('zone', true);
				$zone->initCity();

				$list = $zone->getZoneList(0);
				foreach($list as $zid => $mainZone){
					$zone_all = isset($deliver[$zid]['all_zone']) ? $deliver[$zid]['all_zone'] : 0;
			?>
				<tr>
                	<td nowrap valign="top" width="10%"> &nbsp; <?=$mainZone->name;?> &nbsp; </td>
                    <td nowrap valign="top" width="8%">
                		<?php echo store_checkbox('zone_all', '全区', $zid, $zone_all);?> &nbsp; </td>
                	<td>
                    <div id="zone_div_<?=$zid;?>" style="<?php if($zone_all) echo 'display:none';?>">
                    <?php
                		$sublist = $zone->getZoneList($zid);
						if(is_array($sublist)){
							foreach($sublist as $subid => $subZone){
	                    		echo store_checkbox('deliver_zone', $subZone->name, $subid, isset($deliver[$subid]));
							}
						}
                    ?>
                    </div>
                    </td>
                </tr>
            <?php
				}
            ?>
            </table>
            </td>
          </tr>
        </table>
      </div>
      <div id="con_one_4" style="display:none">
        <table width="100%" border="0" cellspacing="2" cellpadding="0" id="table4" class="formtable">
          <tr>
            <td width="19%" align="right"><span class="title">餐厅Logo</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%">
            <img width="168" height="134" id="storepic" src="<?=empty($data['picture']) ? STATIC_URL.'img/store_nopic.jpg' : UPLOAD_URL.$data['picture'];?>" />
            <br />
            地址： <input type="text" name="picture" id="picture" size="40" class="skey-l" value="<?=h($data['picture']);?>" />
            <!--<br />
            上传： <input type="file" name="upfile" id="upfile" />
            &nbsp;(168x130) &nbsp;&nbsp; <font color="red">*</font>--></td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">地图标点</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%">

            经度：<input type="text" name="longitude" id="longitude" value="<?=h($data['longitude']);?>" /><br />
            纬度：<input type="text" name="latitude" id="latitude" value="<?=h($data['latitude']);?>" />
            <span class="tips"><a href="javascript:tipsmap('');">打开地图</a></span>

            </td>
          </tr>
          <tr>
            <td width="19%" align="right"><span class="title">备注信息</span></td>
            <td width="1%">&nbsp;</td>
            <td width="80%"><textarea class="stxt" rows="6" cols="40" id="memo" name="memo"><?=h($data['memo']);?></textarea></td>
          </tr>
        </table>
      </div>
    </div>
  </div>
  <div class="blank20"></div>
  <input type="submit" name="dosubmit" value=" 提交 " class="button" />
  <input type="button" onclick="javascript:location.href='<?=Base::adminUrl('store', 'index');?>'" value=" 返回 " class="button" />
<div style="width:420px;height:300px;border:1px solid #AAC;display:none;" id="baidu_map"></div>
</form>

<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.2"></script>
<script type="text/javascript" language="javascript" src="<?=STATIC_URL;?>js/ajaxupload.min.js"></script>
<script type="text/javascript">
function checkSubmit(){
	if ($("#name").val() == "") {
		alert("餐厅名称没有填写！");
		$("#name").focus();
		return false;
	}

	if(!$("#city_deliver").attr("checked")){
		if ($("#zone_id").val() == 0 || $("#subzone_id").val() == 0) {
			alert("餐厅的区域/板块没有选择！");
			return false;
		}
		if ($("#address").val() == "") {
			alert("餐厅的地址没有填写！");
			$("#address").focus();
			return false;
		}
	}
	return true;
}

//提示信息框
function tipsmap(tips){
	art.dialog({
		id:'tipsmap',
		padding:10,
		lock:true,
		ok:true,
		content: document.getElementById("baidu_map"),
		title:'地图标点'
	});
}
function initMap(lng, lat){
	var level = 16;
	if(lng == undefined || !lng || lat == undefined || !lat){
		lng = 121.623517;
		lat = 38.911717;
		level = 13;
	}
	//alert(lng + " " + lat);

	var map = new BMap.Map("baidu_map");//在百度地图容器中创建一个地图
	//var point = new BMap.Point(121.623517, 38.911717);//定义一个中心点坐标
	var point = new BMap.Point(lng, lat);//定义一个中心点坐标

	map.enableDragging();//启用地图拖拽事件，默认启用(可不写)
	map.disableScrollWheelZoom();//启用地图滚轮放大缩小(可不写)
	map.enableDoubleClickZoom();//启用鼠标双击放大，默认启用(可不写)
	map.disableKeyboard();//禁用键盘上下左右键移动地图，默认禁用(可不写)

	//向地图中添加缩放控件
	var ctrl_nav = new BMap.NavigationControl({anchor:BMAP_ANCHOR_TOP_LEFT,type:BMAP_NAVIGATION_CONTROL_SMALL});
	map.addControl(ctrl_nav);

	//向地图中添加缩略图控件
	//var ctrl_ove = new BMap.OverviewMapControl({anchor:BMAP_ANCHOR_BOTTOM_RIGHT,isOpen:1});
	//map.addControl(ctrl_ove);

	//设定地图的中心点和坐标并将地图显示在地图容器中

	map.centerAndZoom(point, level);
	map.panTo(point);

	var iconimg = "http://api.map.baidu.com/library/MarkerTool/1.2/src/images/us_mk_icon.png";
	var iconOld = new BMap.Icon(iconimg, new BMap.Size(23, 25), {anchor: new BMap.Size(9, 25), imageOffset: new BMap.Size(0, -21)});
	var iconNew = new BMap.Icon(iconimg, new BMap.Size(23, 25), {anchor: new BMap.Size(9, 25), imageOffset: new BMap.Size(-23, -21)});

	//覆盖层
	var markerOld = new BMap.Marker(point);
	var markerNew = new BMap.Marker(point);
	markerOld.setIcon(iconOld);
	markerNew.setIcon(iconNew);
	markerNew.enableDragging(); // 设置标注可拖拽

	map.addOverlay(markerOld);
	map.addOverlay(markerNew);

	markerNew.addEventListener("mouseup", function(e){
		var flag = confirm("您确定标注位置？：" + this.getPosition().lng + ", " + this.getPosition().lat);
		if(flag){
			markerOld.setPosition(markerNew.getPosition());
			$("#longitude").val(this.getPosition().lng);
			$("#latitude").val(this.getPosition().lat);
		}
	});
}

$(document).ready(function() {
	//图片上传
	new AjaxUpload($("#upfile"), {
		action: '?c=upload&a=thumb',
		name: 'picture',
		data: {
			'width'   : 168,
			'height'  : 130,
			'dosubmit': 'yes'
		},
		autoSubmit: true,
		responseType: 'json',
		onSubmit : function(file, ext){
			this.disable();
		},
		onComplete: function(file, response){
			this.enable();
			if(response.err == ""){
				alert("OK");
				$('#storepic').attr('src', '<?=UPLOAD_URL;?>' + response.msg.url);
				$('#picture').val(response.msg.url);
			}else if(response.err){
				alert(response.err);
			}else{
				alert("文件上传接口错误，请重试！");
			}
		}
	});

	//配送规则
	$("#order_timetype_0").change(function(){
		if(this.checked){
			$("#delivery_div_type").hide();
		}else{
			$("#delivery_div_type").show();
		}
	});

	//Checkbox选中状态
	$("input[type=checkbox]").change(function(){
		var label = $(this).next();
		if($(this).attr("checked")){
			label.css({"color":"blue","font-weight":"bold"});
		}else{
			label.css({"color":"grey","font-weight":"normal"});
		}
	});

	//配送区域相关
	$("#city_deliver").change(function(){
		if(this.checked){
			$("#zone_deliver").hide();
		}else{
			$("#zone_deliver").show()
		}
	});
	$("input[id^='zone_all']").change(function(){
		var zid = $(this).val();
		if(this.checked){
			$("#zone_div_" + zid).hide();
		}else{
			$("#zone_div_" + zid).show();

		}
	});

	//初始化map
	$("#baidu_map").show();
	initMap($("#longitude").val(), $("#latitude").val());
	$("#baidu_map").hide();


	$("#longitude, #latitude").blur(function(){
		//初始化map
		$("#baidu_map").show();
		initMap($("#longitude").val(), $("#latitude").val());
		$("#baidu_map").hide();
	});

});

</script>

<?php
	//
	function store_checkbox($name, $label, $value, $checked){
		$style   = $checked ? ' style="color:blue;font-weight:bold"' : '';
		$checked = $checked ? ' checked' : '';
		$id  = $name. '_' .$value;
		$str = '<input type="checkbox" name="' .$name. '[]" id="' .$id. '" value="' .$value. '"' .$checked.' />';
		$str.= '<label for="' .$id. '"' .$style. '>'.h($label).'</label> &nbsp;';
		return $str;
	}

	function store_time_option($from, $to, $time){
		for($i=$from*2;$i<=$to*2;$i++){
			$tmp = date("H:i", $i*1800 + 3600*16);
			$sel = ($time == $tmp) ? ' selected' : '';
			echo '<option value="' .$tmp. '"' .$sel. '>' .$tmp. '</option>';
		}
	}
?>